<template lang="html">
  <div class="prd_item" @click="goProduct(item)">
      <div class="prd_img_box">
        <img class="prd_img" v-bind:src="item.product_image" />
      </div>
      <div class="prd_info">
        <div class="prd_info_left">
          <div class="prd_name">{{item.product_short_name}}</div>
          <div class="prd_tips">{{item.product_tips}}</div>
        </div>
        <div class="prd_pross">
          <div class="prd_pross_msk" :style="{width: rate + '%'}"></div>
          <span class="sale_num"  v-if="itemtype === 'new'">已抢{{item.product_sale_num}}</span>
          <span class="sale_num"  v-if="itemtype === 'limit'">剩余{{item.quantity - item.product_sale_num}}</span>
        </div>
      </div>
      <div class="prd_bottom"  v-if="itemtype === 'new'">
        <div class="price">
          <span class="prd_amount">¥{{item.product_unit_price}}</span>
          <span class="prd_price_h">/</span>
          <span class="prd_old_price">市场价:{{item.product_market_price}}</span>
        </div>
        <div class="vip_btn">
          <div class="vip_buy" v-if="is_vip && item.share_profit">购买省{{item.buy_profit ? '¥' + item.buy_profit : ''}}</div>
          <div class="novip_buy" v-if="!is_vip || (is_vip && !item.share_profit)">立即抢购</div>
          <div class="vip_share" v-on:click.stop="sharePrd" v-if="is_vip && item.share_profit">分享赚{{item.share_profit ? '¥' + item.share_profit : ''}}</div>
        </div>
      </div>
      <div class="prd_bottom" v-if="itemtype === 'limit'">
          <div class="price" v-if="!is_vip">
            <span class="prd_amount">¥{{item.product_unit_price}}</span>
            <span class="prd_price_h">/</span>
            <span class="prd_old_price">日常价:{{item.product_market_price}}</span>
          </div>
          <div class="vip_price" v-if="is_vip">
            <span class="prd_amount">¥{{item.product_unit_price}}</span>
            <span class="prd_price_h" v-if="item.share_profit">/</span>
            <span class="prd_old_price">{{item.share_profit ? '赚' + item.share_profit + '元' : ''}}</span>
          </div>
          <div class="vip_btn">
            <div class="vip_buy" v-if="is_vip && item.share_profit">购买省</div>
            <div class="novip_buy" v-if="!is_vip || (is_vip && !item.share_profit)">立即抢购</div>
            <div class="vip_share" v-on:click.stop="sharePrd" v-if="is_vip && item.share_profit">分享赚{{item.share_profit}}</div>
          </div>
        </div>
        <van-actionsheet cancel-text="取消" class="share" v-model="is_open_share" get-container=".exclusive_page" :safe-area-inset-bottom="true">
          <Share :item="item"></Share>
        </van-actionsheet>
    </div>
</template>

<script>
import Share from '@/components/global/share.vue'
export default {
  props: ['itemtype', 'item', 'user_info'],
  components: { Share },
  data () {
    return {
      rate: 0,
      is_vip: true,
      is_open_share: false
    }
  },
  created () {
    if (this.$props.item) {
      var item = this.$props.item
      var rate = item.product_sale_num / item.quantity * 100
      this.rate = rate.toFixed(0)
    }
    if (this.user_info && this.user_info.lev_code === 'COMMON_USER') {
      this.is_vip = false
    } else if (this.user_info.lev_code !== 'COMMON_USER') {
      this.is_vip = true
    }
  },
  methods: {
    sharePrd () {
      this.is_open_share = !this.is_open_share
    },
    goProduct (e) {
      var prdUrl = '/main/shopDetails'
      this.$router.push({ path: prdUrl,
        query: {
          pid: e.product_id,
          item_id: e.item_id,
          activity_id: e.activity_id ? e.activity_id : '',
          activity_name: e.activity_name ? e.activity_name : ''
        }
      })
    }
  }
}
</script>

<style lang="css" scoped>
</style>
